#include "heroplane.h"
#include "config.h"
#include <QString>

heroplane::heroplane()
{
    m_plane.load(HERO_PATH);
    m_x=(gamewidth-m_plane.width())*0.5;
    m_y=(gameheight-m_plane.height());
    m_Rect.setWidth(m_plane.width());
    m_Rect.setHeight(m_plane.height());
    m_Rect.moveTo(m_x,m_y);
    m_speed=HERO_SPEED;

    m_Destroy = false;
    m_destroyFrame = 0;
    m_counter=0;
    m_interval=20;

    for (int i = 1; i <= BOMBMAX; i++) {
        QString path = QString(HEROBOMBPATH).arg(i);
        m_destroyPixmaps[i-1].load(path);
    }
}

void heroplane::shoot()
{
    m_recorder++;
    if(m_recorder<BULLET_INTERVAL)
    {
        return;
    }
    m_recorder=0;
    for(int i=0;i<BULLET_NUM;i++)
    {
        if(m_bullets[i].m_Free)
        {
            m_bullets[i].m_Free=false;
            m_bullets[i].m_x=m_x+m_Rect.width()*0.5;
            m_bullets[i].m_y=m_y;
            break;
        }
    }
}

void heroplane::setPosition(int x, int y)
{
    m_x=x;
    m_y=y;
    m_Rect.moveTo(m_x,m_y);
}
